import time
from concurrent.futures import ThreadPoolExecutor, as_completed


def run(i):
    print(f'线程{i}')
    time.sleep(1)
    return i


if __name__ == '__main__':
    t_list = [1, 2, 3, 4, 5]
    pool = ThreadPoolExecutor(3)
    # 方法1-----结果输出，不按顺序
    # all_task = [pool.submit(run, i) for i in t_list]
    # for i in as_completed(all_task):
    #     print(i.result())

    # 方法2-----结果输出，按顺序
    for res in pool.map(run, t_list):
        print(res)
    print('over')
